package com.oc.mba.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.oc.mba.dao.BaseDAOHibernate;
import com.oc.mba.dao.OcBackendUserDAO;
import com.oc.mba.entity.OcBackendUser;
import com.oc.mba.entity.OcOrder;

@Repository
public class OcBackendUserDAOImpl extends BaseDAOHibernate implements OcBackendUserDAO {

	public OcBackendUser findUser(String userName, String password) {
		logger.debug("finding OcBackendUser instance with userName: " + userName + ", password: " + password);
		try {
			String queryString = "from OcBackendUser as model where model.adminName=? and model.password=?";
			List<OcBackendUser> users = getHibernateTemplate().find(queryString, userName, password);
			if (users!=null && users.size()>0) {
				return users.get(0);
			}
		}
		catch (RuntimeException re) {
			logger.error("find by property name failed", re);
			throw re;
		}
		return null;
	}

	
	public List<OcOrder> findByProperty(String propertyName, Object value) {
		logger.debug("finding OcBackendUser instance with property: " + propertyName + ", value: " + value);
		try {
			String queryString = "from OcBackendUser as model where model." + propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		}
		catch (RuntimeException re) {
			logger.error("find by property name failed", re);
			throw re;
		}
	}
}
